/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.magallanes.core;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author Gonzalez
 */
@XStreamAlias("Category")
public class Category implements Comparable<Category> {

    private String name;
    private List<Item> items;

    public Category(String name) {
        this.name = name;
        this.items = new ArrayList<Item>();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Item> getItems() {
        return items;
    }

    public void addItem(Item item) {
        int index = Collections.binarySearch(items, item);
        if (index < 0) {
            index = -index - 1;
        }
        this.items.add(index, item);
    }

    @Override
    public int compareTo(Category o) {
        return this.name.compareTo(o.getName());
    }

    public void deleteItem(Item item) {
        this.items.remove(item);
    }

    @Override
    public String toString() {
        return name;
    }
}
